package com.zx.eval.api.admin;

import com.zx.common.utils.PageUtils;
import com.zx.common.utils.R;
import com.zx.common.utils.ShiroUtils;
import com.zx.eval.entity.QuestionEntity;
import com.zx.eval.service.QuestionService;
import com.zx.sys.user.api.AbstractApi;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;


/**
 * 测评问题表
 *
 * @author LiYe@zx
 * @email ily_hxy@163.com
 * @date 2020-03-29 18:15:40
 */
@RestController
@RequestMapping("sys/question")
public class QuestionApi extends AbstractApi {

    @Autowired
    private QuestionService questionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:question:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = questionService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:question:info")
    public R info(@PathVariable("id") Integer id){
		QuestionEntity evalQuestion = questionService.getById(id);
        return R.ok().put("info", evalQuestion);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:question:save")
    public R save(@RequestBody QuestionEntity question){
        Long userId = ShiroUtils.getUserId();
        question.setCreateTime(new Date());
        question.setCreator(userId);
		questionService.save(question);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:question:update")
    public R update(@RequestBody QuestionEntity question){
        Long userId = ShiroUtils.getUserId();
        question.setUpdateTime(new Date());
        question.setUpdater(userId);
		questionService.updateById(question);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:question:delete")
    public R delete(@RequestBody Integer[] ids){
		questionService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
